/**
 * $Id$
 */
package jm.lib.common.db;

import java.util.List;

import jm.lib.util.StrUtil;

/**
 * @author Jiming Liu
 *
 */
public class SqlUtil {
	
	/**
	 * 
	 * @param columns
	 * @return
	 */
	public static String getColumnsInSql(List<String> columns) {
  	   String[] arr = new String[columns.size()];
  	   columns.toArray(arr);
  	   return getColumnsInSql(arr);
	}
	
	/**
	 * Caution: Never use  
     * 
	 * @param columns
	 * @return
	 */
	public static String getColumnsInSql(String[] columns) {
		StringBuilder sb = new StringBuilder();
		for (String column : columns) {
			if(sb.length() > 0) {
				sb.append("\n, ");
			}
			sb.append(column);
			if (-1 != column.indexOf('_')
					&& -1 == column.toUpperCase().indexOf(" AS ")) {
				sb.append(" AS ");
				sb.append(StrUtil.getPropertyName(column));
			}
		}
//		if (sb.length() > 0) {
//			sb.delete(sb.length() - 3, sb.length() - 1);
//		}
		return sb.toString();
	}
}
